import http from '../request/index'

export default {
  // 获取所有用户
  getUsers(page, size) {
    return http({
      url: `/users?page=${page}&size=${size}`,
    })
  },
  // 获取搜索用户
  getUsersSearch(page, size, keywords) {
    return http({
      url: `/users/search?page=${page}&size=${size}&keyword=${keywords}`,
    })
  },
  // 修改用户选中状态
  putUserSelect(data) {
    return http({
      url: `/users/select`,
      method: 'put',
      data: data,
    })
  },
  // 删除选中用户
  deleteSelectUsers() {
    return http({
      method: 'delete',
      url: `/users/delSelected`,
    })
  },
  // 获取单个用户
  getOneUser(id) {
    return http({
      url: `/users/${id}`,
    })
  },
  //删除单个用户
  delOneUser(id) {
    return http({
      method: 'delete',
      url: `/users/${id}`,
    })
  },
  // 新增用户
  postAddUser(data) {
    return http({
      url: '/users',
      method: 'post',
      data: data,
    })
  },
  // 修改用户
  putModifyUser(id, data) {
    return http({
      url: `/users/${id}`,
      method: 'put',
      data: data,
    })
  },
  // 获取文章类型和该类型文章的数目
  getEchartCircleData() {
    return http({
      url: '/cate',
    })
  },
  // 按月份获取每个月的文章数目
  getEchartBarData() {
    return http({
      url: '/cate/output',
    })
  },
  // 修改当前用户信息
  putCurrentUser(data) {
    return http({
      url: '/userchange',
      method: 'put',
      data: data,
    })
  },
  // 删除选中文章
  delSelectArticles() {
    return http({
      url: '/posts/delSelected',
      method: 'delete',
    })
  },
  // 修改文章状态
  putArticlesSelect(data) {
    return http({
      url: `/posts/select`,
      method: 'delete',
      data: data,
    })
  },
  // 获取所有文章
  getAllArticles(page, size) {
    return http({
      url: `/posts?page=${page}&size=${size}`,
    })
  },
  // 关键字搜索文章
  getSearchArticles(page, size, keywords) {
    return http({
      url: `/posts/search?page=${page}&size=${size}&keywords=${keywords}`,
    })
  },
  // 删除单个文章
  delOneArticle(id) {
    return http({
      url: `/posts/${id}`,
      method: 'delete',
    })
  },
  // 删除文章详情的图片
  delArticlePhoto(data) {
    return http({
      url: '/postadd/del',
      method: 'post',
      data: data,
    })
  },
  // 获取文章类名
  getArticlesType(page, size) {
    return http({
      url: `/category?page=${page}&size=${size}`,
    })
  },
  // 新增文章
  postAddArticle(data) {
    return http({
      method: 'post',
      url: '/postadd',
      data: data,
    })
  },
  // 查询单个文章
  getOneArticle(id) {
    return http({
      url: `/revision/${id}`,
    })
  },
  // 编辑单个文章详情
  putOneArticle(id, data) {
    return http({
      method: 'put',
      url: `/revision/${id}`,
      data: data,
    })
  },
  // 获取所有的文章分类
  getAllType(page, size) {
    return http({
      url: `/category?page=${page}&size=${size}`,
    })
  },
  // 根据关键词搜索分类
  getSearchType(page, size, keywords) {
    return http({
      url: `/category/search?page=${page}&size=${size}&keywords=${keywords}`,
    })
  },
  // 新增分类
  postAddType(data) {
    return http({
      url: '/category',
      method: 'post',
      data: data,
    })
  },
  // 根据id获取分类
  getOneType(id) {
    return http({
      url: `/category/${id}`,
    })
  },
  // 根据id修改分类
  putModifyType(id, data) {
    return http({
      url: `/category/${id}`,
      method: 'put',
      data: data,
    })
  },
  // 登录页面
  postLogin(data) {
    return http({
      url: '/login',
      method: 'post',
      data: data,
    })
  },
  // 注册页面,验证用户名是否重复
  getVerifyUser(value) {
    return http({
      url: `/enroll/checkName?username='${value}'`,
    })
  },
  // 注册用户
  postEnrollUser(data) {
    return http({
      url: '/enroll',
      method: 'post',
      data: data,
    })
  },
}
